package cn.caidabao.gb.component.sip.server.request.send;

import cn.caidabao.gb.bean.GBSipRegisterSession;
import cn.caidabao.gb.bean.OGSipCallIdCallBack;
import cn.caidabao.gb.bean.PlaybackCmdObject;
import cn.caidabao.gb.component.sip.CustomSipServer;
import cn.caidabao.gb.component.sip.server.storage.CallBackStorage;
import cn.caidabao.gb.component.sip.server.storage.SessionStorage;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Component
public class PlaybackCmdSender extends RequestSender<PlaybackCmdObject,Object>{
    @Resource
    private CustomSipServer sipServer;
    @Resource
    private SessionStorage sessionStorage;
    @Resource
    private CallBackStorage callBackStorage;
    @Override
    public OGSipCallIdCallBack<Object> sendAsync(GBSipRegisterSession gbSipRegisterSession, PlaybackCmdObject extraData) {
        OGSipCallIdCallBack channelCallBack = callBackStorage.getCallBackByChannelId(extraData.getDeviceId());
        String callId = sipServer.sendPlaybackCmd(channelCallBack.getChannelId(),
                 gbSipRegisterSession.getIp()+":"+ gbSipRegisterSession.getPort(),
                 extraData.getCmdContent(),channelCallBack.getCSeq()+1,channelCallBack.getCallId());
        callBackStorage.putCallBack(callId,channelCallBack);
        return channelCallBack;
    }
}
